//
//  UIImage+OMTBundle.m
//  OMTImagePicker
//
//  Created by yizhaorong on 2017/12/12.
//

#import "UIImage+OMTBundle.h"
#import "NSBundle+OMTImagePicker.m"

@implementation UIImage (OMTBundle)

+ (instancetype)omt_bundleImageNamed:(NSString *)name {
    NSString *pathExtension = name.pathExtension;
    NSString *imageName = [NSString stringWithFormat:@"%@@2x.png", name];
    if (pathExtension.length > 0) {
        imageName = name;
    }
    
    static NSBundle *bundle = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        bundle = [NSBundle bundleWithPath:[[NSBundle omt_imagePickerBundle] pathForResource:@"images" ofType:nil]];
    });
    NSString *path = [bundle URLForResource:imageName withExtension:nil].path;
    if (path) {
        return [self imageWithContentsOfFile:path];
    }
    return nil;
}

@end
